package com.healthy.education.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.education.domain.ArticleCategories;
import com.healthy.education.service.IArticleCategoriesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 文章分类Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/ArticleCategories")
public class ArticleCategoriesController extends BaseController
{
    @Autowired
    private IArticleCategoriesService articleCategoriesService;

    /**
     * 查询文章分类列表
     */
    @RequiresPermissions("education:ArticleCategories:list")
    @GetMapping("/list")
    public TableDataInfo list(ArticleCategories articleCategories)
    {
        startPage();
        List<ArticleCategories> list = articleCategoriesService.selectArticleCategoriesList(articleCategories);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @RequiresPermissions("education:ArticleCategories:export")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleCategories articleCategories)
    {
        List<ArticleCategories> list = articleCategoriesService.selectArticleCategoriesList(articleCategories);
        ExcelUtil<ArticleCategories> util = new ExcelUtil<ArticleCategories>(ArticleCategories.class);
        util.exportExcel(response, list, "文章分类数据");
    }

    /**
     * 获取文章分类详细信息
     */
    @RequiresPermissions("education:ArticleCategories:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleCategoriesService.selectArticleCategoriesById(id));
    }

    /**
     * 新增文章分类
     */
    @RequiresPermissions("education:ArticleCategories:add")
    @Log(title = "文章分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleCategories articleCategories)
    {
        return toAjax(articleCategoriesService.insertArticleCategories(articleCategories));
    }

    /**
     * 修改文章分类
     */
    @RequiresPermissions("education:ArticleCategories:edit")
    @Log(title = "文章分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleCategories articleCategories)
    {
        return toAjax(articleCategoriesService.updateArticleCategories(articleCategories));
    }

    /**
     * 删除文章分类
     */
    @RequiresPermissions("education:ArticleCategories:remove")
    @Log(title = "文章分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleCategoriesService.deleteArticleCategoriesByIds(ids));
    }
}
